package DAO;/*
@author joker
@create 2022-03-09 15:42
*/

import javabean.statementOfIncome;

import java.util.Date;
import java.util.List;

public class StatementOfIncomeDAO extends BasicDAO<statementOfIncome> {
    //1. 就有BasicDAO的所有方法
    //2. 根据业务需求,可以编写特有的的方法
    /*管理员模块功能*/

    /**
     * 获得所有账单信息
     */
    public List<statementOfIncome> getAllState() {
        StatementOfIncomeDAO statementOfIncomeDAO = new StatementOfIncomeDAO();
        String sql = "select * from statementofincome";
        List<statementOfIncome> aa = null;
        try {
            aa = statementOfIncomeDAO.queryMultiply(sql, statementOfIncome.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return aa;
    }


    /**
     * 获取单个用户的账单信息
     */
    public List<statementOfIncome> getSingleUserAllState(String userID) {
        StatementOfIncomeDAO statementOfIncomeDAO = new StatementOfIncomeDAO();
        String sql = "select * from statementofincome where userID = ?";

        return statementOfIncomeDAO.queryMultiply(sql, statementOfIncome.class, userID);
    }

    //插入账单信息 用户名,车牌号,日期自动加入,收入还是支出,用正负号表示,返回1表示成功
    public int insertBill(String userID, String CarID1, String CarID2, String CarID3, String Money) {
        StatementOfIncomeDAO statementOfIncomeDAO = new StatementOfIncomeDAO();
        java.util.Date date = new Date();
        String year = String.format("%tY", date);

        String month4 = String.format("%tm", date);

        String day = String.format("%te", date);
        String today = year + "-" + month4 + "-" + day;
        System.out.println(year + "-" + month4 + "-" + day);
        String sql = "insert into statementofincome (userid,carid1,carid2,carid3,date,money) values(?,?,?,?,?,?)";
        return statementOfIncomeDAO.update(sql, userID, CarID1, CarID2, CarID3, today, Money);
    }

}
